package com.lancoo.znbkxx.teacher.ui.activity

import android.annotation.SuppressLint
import android.view.View
import android.webkit.WebChromeClient
import android.webkit.WebSettings
import android.webkit.WebViewClient
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.base.BaseVMActivity
import com.lancoo.znbkxx.teacher.databinding.ActivityHelpBinding
import com.lancoo.znbkxx.teacher.viewmodel.UserInfoViewModel
//import com.tencent.smtt.sdk.WebChromeClient
//import com.tencent.smtt.sdk.WebSettings
//import com.tencent.smtt.sdk.WebViewClient
import kotlinx.android.synthetic.main.activity_help.*

class PrivacyActivity : BaseVMActivity<UserInfoViewModel, ActivityHelpBinding>() {

    private val TERMS = "file:///android_asset/terms.html"
    private val PRIVACY = "file:///android_asset/privacy.html"

    override fun providerVMClass(): Class<UserInfoViewModel>? {
        return UserInfoViewModel::class.java
    }

    override fun setLayoutID(): Int {
        return R.layout.activity_help
    }

    @SuppressLint("SetJavaScriptEnabled")
    override fun initView() {
        val isPrivacy = intent.extras!!.getBoolean("isPrivacy", true)
        binding.sbtnBack.setOnClickListener { v ->
            if (wv.canGoBack()) run { wv.goBack() } else {
                finish()
            }
        }

        binding.sbtnAgree.clearAnimation()
        binding.sbtnAgree.visibility = View.GONE

        binding.wv.apply {
            settings.javaScriptEnabled = true
            settings.useWideViewPort = true
            settings.layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS
            settings.loadWithOverviewMode = true
            webChromeClient = WebChromeClient()
            webViewClient = WebViewClient()
        }
        if (isPrivacy) {
            binding.wv.loadUrl(PRIVACY)
        } else {
           binding.wv.loadUrl(TERMS)
        }
    }

    override fun onBackPressed() {
        if (wv.canGoBack()) {
            wv.goBack()
        } else {
            finish()
        }
    }
}